<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加服务</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i>
    首页
    <span class="c-gray en">&gt;</span>
    会员管理
    <span class="c-gray en">&gt;</span>
    办卡管理
    <span class="c-gray en">&gt;</span>
    修改会员卡
</nav>
<div class="page-container">
    <div class="form-unit">基本信息</div>
    <!-- 年卡 -->
    <div id="cardManageEditYearCard" style="display: none;">
        <form  method="post" class="form form-horizontal" id="cardManageEditYearCard-form-add">
            <input id="cardManageEditYearCardCardId" name="cardId" style="display: none"/>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">手机号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageEditYearCardPhone" name="phone">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">车牌号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageEditYearCardCarNo" name="carNo">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">会员卡号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageEditYearCardCardNo" name="cardNo">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">使用次数：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageEditYearCardConsumeNum" name="consumeNum">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">开卡时间：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" onfocus="WdatePicker({readOnly:true,dateFmt: 'yyyy-MM-dd HH:mm:ss' })" readonly="readonly" class="form-control Wdate" value="" name="addTimes" id="cardManageEditYearCardAddTime">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">到期时间：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" onfocus="WdatePicker({readOnly:true,dateFmt: 'yyyy-MM-dd HH:mm:ss' })" readonly="readonly" class="form-control Wdate" value="" name="endTimes" id="cardManageEditYearCardEndTime">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">会员卡描述：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <textarea id="cardManageEditYearCardRemark" name="remark" cols="60" rows="5" class="textarea valid" placeholder="请输入会员卡的描述..."></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input onclick="cardManageEditFun.submitYearCard();return false;" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"/>
                </div>
            </div>
        </form>
    </div>
    <!-- 储值卡 -->
    <div id="cardManageEditValueCard" style="display: none;">
        <form  method="post" class="form form-horizontal" id="cardManageEditValueCard-form-add">
            <input id="cardManageEditValueCardCardId" name="cardId" style="display: none"/>
            <input id="cardManageEditValueCardConsumeNum" name="consumeNum" style="display: none"/>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">手机号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageEditValueCardPhone" name="phone">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">车牌号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageEditValueCardCarNo" name="carNo">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">会员卡号：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageEditValueCardCardNo" name="cardNo">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">储值余额：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" class="form-control" value="" placeholder="必填项" id="cardManageEditValueCardRemainNum" name="remainNum">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">开卡时间：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" onfocus="WdatePicker({readOnly:true,dateFmt: 'yyyy-MM-dd HH:mm:ss' })" readonly="readonly" class="form-control Wdate" value="" name="addTimes" id="cardManageEditValueCardAddTime">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">到期时间：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <input type="text" onfocus="WdatePicker({readOnly:true,dateFmt: 'yyyy-MM-dd HH:mm:ss' })" readonly="readonly" class="form-control Wdate" value="" name="endTimes" id="cardManageEditValueCardEndTime">
                </div>
            </div>
            <div class="form-group">
                <label class="control-label col-xs-4 col-sm-3">会员卡描述：</label>
                <div class="formControls col-xs-4 col-sm-4">
                    <textarea id="cardManageEditValueCardRemark" name="remark" cols="60" rows="5" class="textarea valid" placeholder="请输入会员卡的描述..."></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input onclick="cardManageEditFun.submitValueCard();return false;" class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"/>
                </div>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
    /*办卡管理，修改页面 cardManageEditFun*/
    var cardManageEditFun;

    cardManageEditFun={
        init : function () {
            var cardId = sessionStorage.getItem("cardManage-cardId");

            $.ajax({
                type: "get",
                url: "cust/getCustCardByCardId",
                data: {cardId:cardId},
                dataType: "json",
                success : function(json) {
                    if (json.state) {
                        var data = json.data;
                        if(data.cardType == 1){
                            $("#cardManageEditValueCard").show();
                            $("#cardManageEditValueCardCardId").val(data.cardId);
                            $("#cardManageEditValueCardPhone").val(data.phone);
                            $("#cardManageEditValueCardCarNo").val(data.carNo);
                            $("#cardManageEditValueCardCardNo").val(data.cardNo);
                            $("#cardManageEditValueCardRemainNum").val(data.remainNum/100);
                            $("#cardManageEditValueCardConsumeNum").val(data.consumeNum/100);
                            $("#cardManageEditValueCardAddTime").val(data.addTime);
                            $("#cardManageEditValueCardEndTime").val(data.endTime);
                            $("#cardManageEditValueCardRemark").val(data.remark);
                        }else {
                            $("#cardManageEditYearCard").show();
                            $("#cardManageEditYearCardCardId").val(data.cardId);
                            $("#cardManageEditYearCardPhone").val(data.phone);
                            $("#cardManageEditYearCardCarNo").val(data.carNo);
                            $("#cardManageEditYearCardCardNo").val(data.cardNo);
                            $("#cardManageEditYearCardAddTime").val(data.addTime);
                            $("#cardManageEditYearCardConsumeNum").val(data.consumeNum/100);
                            $("#cardManageEditYearCardEndTime").val(data.endTime);
                            $("#cardManageEditYearCardRemark").val(data.remark);
                        }
                    } else {
                        alert(json.message);
                    }
                },
                error:function () {
                    alert("error");
                }
            });

        },
        //提交(年卡)
        submitYearCard : function () {
            var temp = $("#cardManageEditYearCard-form-add").serializeArray();
            for(var i =0;i<temp.length;i++){
                if(temp[i].name == 'consumeNum'){
                    temp[i].value = temp[i].value*100;
                }
            }
            $.ajax({
                type: "GET",
                url: "cust/updateYearCard",
                data: temp,
                dataType: "json",
                success: function (data) {
                    if (data.state) {
                        layer.msg(data.message, {icon: 1});

                        //关闭新增窗口
                        removeIframe();
                        platformClientCardManageFun.searchAction();
                    } else {
                        alert(data.message);
                    }
                },
                error: function () {
                    alert("error2");
                }
            });
        },
        //提交(储值卡)
        submitValueCard : function () {
            var temp = $("#cardManageEditValueCard-form-add").serializeArray();
            for(var i =0;i<temp.length;i++){
                if(temp[i].name == 'consumeNum'){
                    temp[i].value = temp[i].value*100;
                }
                if(temp[i].name == 'remainNum'){
                    temp[i].value = temp[i].value*100;
                }
            }
            $.ajax({
                type: "GET",
                url: "cust/updateValueCard",
                data: temp,
                dataType: "json",
                success: function (data) {
                    if (data.state) {
                        layer.msg(data.message, {icon: 1});

                        //关闭新增窗口
                        removeIframe();
                        platformClientCardManageFun.searchAction();
                    } else {
                        alert(data.message);
                    }
                },
                error: function () {
                    alert("error2");
                }
            });
        }
    };
    cardManageEditFun.init();
</script>
</body>
</html>